<?php

require_once('../../config/maptrick.conf.php');
require_once(SITE_ROOT . 'class/bean/Alliance.class.php');
require_once(SITE_ROOT . 'class/db/DBAlliance.class.php');
require_once(SITE_ROOT . 'class/db/DBAllianceMember.class.php');

try {
	if ($_GET["pass"] != SCRIPT_PWD) die("Incorrect password");
	
	$dballiance = new DBAlliance();
	$dballiancemember = new DBAllianceMember();
	
	$alliances = $dballiance->getAlliances();
	
	foreach ($alliances as $alliance) {
		if ($alliance->getUpdate() < strtotime("-30 days")) {
			$dballiance->deleteAlliance($alliance);
			$dballiancemember->deleteAllianceMembership($alliance);
			echo "Alliance (ID:" . $alliance->getAllianceID() . ") deleted!<br />";
		}
	}
	echo "Alliance cleanup done";
	
}
catch (Exception $e) {
	echo $e->getMessage();
	echo "Alliance cleanup failed!";
}

?>